package com.angis.fx.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Random;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.content.Context;
import android.telephony.TelephonyManager;

public class CommonUtil {

	public static TelephonyManager getTelephoneManager(Context pContext) {
		TelephonyManager lTm = (TelephonyManager) pContext
				.getSystemService(Context.TELEPHONY_SERVICE);
		return lTm;
	}

	public static String getCurrentDate() {
		Calendar lCalendar = Calendar.getInstance();
		SimpleDateFormat lSdf = new SimpleDateFormat("hh:mm");
		String lDate = lSdf.format(lCalendar.getTime());
		return lDate;
	}

	public static String randomUUID() {
		return UUID.randomUUID().toString();
	}

	public static String randomNumber(int digit) {
		Random lRandom = new Random();
		char[] buf = new char[digit];
		char[] symbols = new char[10];
		for (int idx = 0; idx < 10; ++idx)
			symbols[idx] = (char) ('0' + idx);
		for (int idx = 0; idx < buf.length; ++idx)
			buf[idx] = symbols[lRandom.nextInt(symbols.length)];
		return new String(buf);
	}

	public static boolean validateIP(String pIp) {
		Pattern lPattern = Pattern
				.compile("\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b");
		Matcher lMatcher = lPattern.matcher(pIp);
		return lMatcher.matches();
	}

}
